<template>
  <div>
      <vol-box :lazy="true"
             :model.sync="model.box2"
             title="添加标签"
             :height="200"
             :width="500"
             :padding="15">
            <VolForm ref="myform"
                    :loadKey="loadKey"
                    :formFileds="formFileds"
                    :formRules="formRules"></VolForm>
        <div slot="footer">
            <Button type="success"
                    @click="getForm">保存</Button>
            <Button type="error"
                    
                    @click="reset">重置</Button>
            <Button type="info"
                    @click="model.box2=false">
              <Icon type="md-close" />关闭
            </Button>
        </div>
        

    </vol-box>

        
  </div>
</template>
<script>
import VolForm from "@/components/basic/VolForm.vue";
import VolBox from "@/components/basic/VolBox.vue";
import VolTable from "@/components/basic/VolTable.vue";

export default {
  components: { VolForm,"vol-box": VolBox,VolTable  },
  methods: {
    addrows(item){
      this.$refs.tables.addRow(item)
    },
    getForm () {
      if (!this.$refs.myform.validate()) {
        return;
      }
      let formData = {
            mainData:this.formFileds,
           // detailData: this.$refs.tables.tableData,
            delKeys: null
            };
        this.http.post("api/Mall_label/Add", formData, true).then(x => {
        if (!x.status) return this.$message.error(x.message);
        this.$message.success(x.message);
        if(x!=null){
          this.goosat();
        }
        // this.$emit("parentCall",x.data);
        })
         this.model.box2 = false;
    },
     goosat(){
           
           this.http.post("api/Dictionary/GetVueDictionary",["Label"],false).then(reslut=>
           {
             
                  let datas=[];
                  reslut.find(item1 => item1.dicNo == "Label").data.forEach(item1=>
                  {
                    this.$emit("parentCall",item1);
                    console.log(item1);
                  })
           });
        },
    reset () {
      //重置表单，重置时可指定重置的值，如果没有指定重置的值，默认全部清空
      //let data = { Variety: "1", AvgPrice: 888 };
      this.$refs.myform.reset(data);
     // this.$message.error("表单已重置");
    },
    getFormOption(field) {
        let option;
        this.formRules.forEach(x => {
            x.forEach(item => {
                if (item.field == field) {
                    option = item;
                }
            })
        })
        return option;
        },
     
    open1 () {
      //this.getinitDictionary();
      this.model.box2 = true;
        //获取当前弹出框是新建还是编辑状态
        let isEDIT = true;
        var selectOption = this.getFormOption('labelName');  
       if(!isEDIT) {
            selectOption.onInput = (val) => {    
            this.formFileds.labelCode=this.base.chineseToPinYin(val);
            }
        } 
        var Code = this.getFormOption('labelCode');
        this.$set(Code, "disabled", true)
    },
      getinitDictionary(){
      let distributor=this.getFormOption("distributor");
      let paytype=this.getFormOption("pay_type");
       this.http.post("api/Dictionary/GetVueDictionary",["distributorList","reservationType"],false).then(reslut=>{
              let datas=[];
              reslut.find(item1 => item1.dicNo == "distributorList").data.forEach(item1=>{
                  let items={}
                  items.value=item1.value;
                  items.key=item1.key;
                  datas.push(items)
                })
              //distributor.data=datas;
               let data1s=[];
                reslut.find(item1 => item1.dicNo == "reservationType").data.forEach(item1=>{
                  let items={}
                  items.value=item1.value;
                  items.key=item1.key;
                  data1s.push(items)
                })
             // paytype.data=data1s;
       });
    },
  },
  data () {
    return {
      specList:[],
      table1url:"",
      model: {
        box2: false,
        box1:false,
      },
      //tableData:[],
      loadKey: true,
      formFileds: {
        labelName:"",
        labelCode:"",
        isAvailable:""
      },
      formRules: [
        //两列的表单，formRules数据格式为:[[{},{}]]
         [{"title":"标签名称","required":true,"field":"labelName","type":"text",colSize:12},],
         [{"title":"标签编码","field":"labelCode","type":"text"},
         {"title":"是否可用","required":true,"field":"isAvailable","type":"switch","dataKey":"enable"},]
        ], 
        show:true   
    };
  },
  // open(row){
  //     this.title=row;
  //       this.model.box1=true;

        
        
        
  //   }
};
</script>
